#pragma once
#include "EngineHead.h"
#include "SceneManagerInterface.h"
#include "SceneNode.h"
#include "Camera.h"

namespace mini
{
	class CActor;
	class CSceneControl;
	class CLightActor;
	class CScene
	{
	public:
		CScene();
		virtual ~CScene();
		bool    load(const std::string& fileName);
		bool	load();
		bool	unload();
		void	save();
		void	saveAs(const std::string& fileName);
		void	reload();
		void	addSceneControl(CSceneControl* pSceneControl);
		
		bool    addEntity(CEntity* pEntity);
		bool    removeEntity(CEntity* pEntity);
		bool	addActor(CActor* pEntity);
		bool	removeActor(CActor* pEntity);
		bool	addRenderNode(CRenderNode* pRenderNode);
		bool	removeRenderNode(CRenderNode* pRenderNode);

		void	setCamera(CCamera* pCamera);
		void	removeCamera(CActor* pCamera);
		void	addLight(CLightActor* pLight);
		void	removeLight(CLightActor* pLight);
		bool	isInit();

		CActor* findActor(CActor* pEntity);
		CActor* findActorByUUID(UINT32 uuid);
		CActor* findActorByName(const std::string& strActorName);
		CRenderNode* getRenderNodeByActor(CActor* pActor);
		CRenderViewport*	findViewportByName(const std::string& strViewportName )const;
		CCamera* getCamera();

		void				releaseSceneActors();
		void				updateScene(float fDeltaTime);

		void				setStartPt(CVector& pt);
		CVector&			getStartPt();
		const std::string&	getSceneName()const;
		CEntity*			calculationPickEntity(float x, float y);
		virtual void		processMsg(event& msg);
		std::set<CRenderNode*>		getRenderNodes() const;
	private:
		bool	addRenderViewport(CActor* pViewport);
		bool	removeRenderViewport(CActor* pViewport);
		void	removeAllRenderViewport();

	private:
		std::string							mSceneName;
		std::string							mSaveName;
		std::list<CSceneManagerInterface*>	mSceneInterface;
		std::list<CCamera*>					mCameras;
		std::list<CLightActor*>				mLights;
		std::map<UINT32, CActor*>			mActors;
		std::map<UINT32, CEntity*>			mEntities;
		std::set<CRenderNode*>				mRenderNodes;
		std::set<CRenderViewport*>			mRenderViewports;
		CCamera*							mActiveCamera;
		CVector								mStartPt;
		std::string							mstrDefaultPath = "resource/Scene/";
		bool								mInitialise = false;
		CSceneControl*						mpSceneControl = nullptr;
		//CVector								mLookAtPt;
	};
}
